package baidu.util;


import com.alibaba.fastjson.JSONObject;

/**
 * Created by LeeXyan on 2017/04/08 16:50
 * 根据经纬坐标 得到的地址名称 方法
 */
public class BaiDuUtil {
    public static String getCity(String lat, String lng) {
        JSONObject obj = getLocationInfo(lat, lng).getJSONObject("result")
                .getJSONObject("addressComponent");
        return obj.getString("city");
    }
    public static JSONObject getLocationInfo(String lat, String lng) {
        String url = "http://api.map.baidu.com/geocoder/v2/?location=" + lat + ","
                + lng + "&output=json&ak=" + Config.BAIDU_GEOCONV_KEY+"&pois=0";
        JSONObject obj = JSONObject.parseObject(HttpUtil.getRequest(url));
        return obj;
    }
    public static void main(String[] args) {
        System.out.println(BaiDuUtil.getCity("36.400", "117.000"));
        System.out.println(BaiDuUtil.getCity("35.400", "117.000"));
        System.out.println(BaiDuUtil.getCity("34.400", "117.000"));
    }
}
